const express = require("express")
const app = express()
const  bodyParser = require('body-parser')
require("body-parser-xml")(bodyParser);
var path = require('path');
app.use(express.json())
app.use(require('cors')())

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/uploads',express.static(__dirname + '/uploads'))

app.use(bodyParser.xml({
  limit: "1MB",   // Reject payload bigger than 1 MB
  xmlParseOptions: {
    normalize: true,     // Trim whitespace inside text nodes
    normalizeTags: true, // Transform tags to lowercase
    explicitArray: false // Only put nodes in array if >1
  },
  verify: function(req, res, buf, encoding) {
    if(buf && buf.length) {
      // Store the raw XML
      req.rawBody = buf.toString(encoding || "utf8");
    }
  }
}));

app.use(bodyParser.json());
require('./plugins/db')(app)

require('./router/wx/index')(app)

require('./router/server/index')(app)


module.exports  = app;